package com.summary.richtext.controller;

import com.summary.richtext.entity.Student;
import com.summary.richtext.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Api(tags = "Excel富文本导入导出")
@RestController
@RequestMapping("/poi/excelUtil")
public class MainController {

    @Autowired
    private StudentService studentService;

    /**
     * excel导入(学生信息表)
     * @param file
     * @return
     */
    @ApiOperation(value = "excel导入(学生信息表)")
    @PostMapping(path = "/importExcelFile/student")
    public Object newImportFile(MultipartFile file) throws Exception {
        List<Student> list = studentService.realizationImprot(file);//由于没有数据库，这里以获取excel数据为导入标准
        return list;
    }

    /**
     * excel导出(学生信息表)
     * @param response
     */
    @ApiOperation(value = "excel导出(学生信息表)")
    @GetMapping(value = "/exportExcelFile/student")
    public void ExportExcelFile(HttpServletResponse response){
        try {
            studentService.realizationExcel(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
